﻿using Microsoft.Practices.ObjectBuilder2;
using Microsoft.Practices.Unity;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace FileSystem
{
    class OrderedParametersOverride : ResolverOverride
    {
          #region Privte Fields
        private readonly Queue<InjectionParameterValue> parameterValues;
        #endregion

        #region Constructors

        /// <summary>
        /// Initializes a new instance of the <see cref="OrderedParametersOverride"/> class.
        /// </summary>
        /// <param name="parameterValues">The parameter values.</param>
        public OrderedParametersOverride(IEnumerable<object> parameterValues)
        {
            this.parameterValues = new Queue<InjectionParameterValue>();
            foreach (var parameterValue in parameterValues)
            {
                this.parameterValues.Enqueue(InjectionParameterValue.ToParameter(parameterValue));
            }
        }

        #endregion

        #region Overridden Methods

        /// <summary>
        /// Gets the resolver.
        /// </summary>
        /// <param name="context">The context.</param>
        /// <param name="dependencyType">Type of the dependency.</param>
        /// <returns></returns>
        public override IDependencyResolverPolicy GetResolver(IBuilderContext context, Type dependencyType)
        {
            if (parameterValues.Count < 1)
                return null;

            var value = this.parameterValues.Dequeue();
            return value.GetResolverPolicy(dependencyType);
        }

        #endregion

    }
}
